/**
 * @author 岳晓磊
 */
 /**
  * 生成表格
  */
var sort = null,bbar="",grid = new Ext.grid.GridPanel();  
function inituserlist(){
    var dividerUserid = Ext.get('dividerUserid').getValue();
    if(dividerUserid=="recipientUserid"){
		Ext.menu.RangeMenu.prototype.icons = {
		  gt: './ajaxFramework/ext-2.1/img/greater_then.png', 
		  lt: './ajaxFramework/ext-2.1/img/less_then.png',
		  eq: './ajaxFramework/ext-2.1/img/equals.png'
		};
		Ext.grid.filter.StringFilter.prototype.icon = './ajaxFramework/ext-2.1/img/find.png';
		var colModel = new Ext.grid.ColumnModel([
			{header:'下发日期',dataIndex:'beginTime1',menuDisabled : true},
			{header:'完成日期',dataIndex:'endTime1',menuDisabled : true},
			{header:'标题',dataIndex:'subject',menuDisabled : true},
			{header:'下发人',dataIndex:'dividerUsername'},		
			{header:'重要程度',dataIndex:'importLevel1',menuDisabled : true},
			{header:'状态',dataIndex:'currentStatus1',menuDisabled : true},
			{header:'id',dataIndex:'id',hidden:true},
			{header:'操作',dataIndex:'operate',menuDisabled : true,renderer:function(s,m,rec){
			return "<a  href="+"javascript:workDailyTo('"+rec.data.id+"','recipientUserid')>查看</a>";
			}}
		]);
		var filters = new Ext.grid.GridFilters({
			 cleanParams: function(p) {  // 清除参数的方法，要保留PagingToolbar分页用的两个参数
			   //var regex = new RegExp("^" + this.paramPrefix + "\[[0-9]+\]");
			   for(var key in p) {
			      if( key != 'start' && key != 'limit' )
			   //if(regex.test(key)) {
			    delete p[key];
			            //}
			               }
	          },
		     buildQuery: function(filters) {	
			  // filters 就是getFilterData返回的值, 代码中push入去的对象
			  var p = {};
			  for(var i=0, len=filters.length; i<len; i++) {
			      var f = filters[i];
			      
			      // 取得在GridFilters中定义的filters中的一个filter
			      var filter = this.getFilter( f.field );
			      // 取得传递到server的参数名称
			      var name = (filter.paramName ? filter.paramName : filter.dataIndex);
			      var value = (filter.paramValue ? filter.paramValue : f.data['value']);
			      
			      if( value != '' ) p[ name ] = value;
			  }
			  return p;
			   },	
			  filters:[
			 	{type: 'string',  dataIndex: 'dividerUsername'}
		]}); 
		var url = Ext.get('url').getValue();
		sort = new Ext.data.JsonStore({
			url:url,
			fields:['beginTime1','endTime1','subject','dividerUsername','importLevel1','currentStatus1','id','operate'],
			root:'root',
			totalProperty:'totalProperty'
		});
		var bbar = new Ext.PagingToolbar({
			pageSize:10,
			store:sort,
			plugins: filters,
			displayInfo:true,
			emptyMsg:'没有记录'
		});
		
	   grid = new Ext.grid.GridPanel({
			title:'工作任务--接受',
			cm:colModel,
			renderTo:'topic-grid',
			store:sort,
			loadMask:true,
			autoHeight:true,
			tbar:[{
				 text: '接受任务',
	             iconCls: 'silk-add',
	             handler:function(){
	             	window.location.href=Ext.get('basePath').getValue()+'daily/workTask/workTaskList.jsp?dividerUserid=recipientUserid';
	             }
			},{
				 text: '下发任务',
	             iconCls: 'silk-add1',
	             handler:function(){
	             	window.location.href=Ext.get('basePath').getValue()+'daily/workTask/workTaskList.jsp?dividerUserid=dividerUserid';
	             }
			}],
			bbar:bbar,
			plugins: filters,
			viewConfig:{
				forceFit:true
			}
		});
		
		if(Ext.get('startid')){
			start = Ext.get('startid').getValue();
			sort.load({params:{start:0, limit: 10},callback:function(){
				grid.hide();
				bbar.hide();
				bbar.changePage(Ext.get('page').getValue());
				grid.show();
				bbar.show();
			}});
			return;
		}
		else
		{
			sort.load({params:{start:0, limit: 10}});
		}   
    }else{
		Ext.menu.RangeMenu.prototype.icons = {
		  gt: './ajaxFramework/ext-2.1/img/greater_then.png', 
		  lt: './ajaxFramework/ext-2.1/img/less_then.png',
		  eq: './ajaxFramework/ext-2.1/img/equals.png'
		};
		Ext.grid.filter.StringFilter.prototype.icon = './ajaxFramework/ext-2.1/img/find.png';
		var colModel = new Ext.grid.ColumnModel([
			{header:'下发日期',dataIndex:'beginTime1',menuDisabled : true},
			{header:'完成日期',dataIndex:'endTime1',menuDisabled : true},
			{header:'标题',dataIndex:'subject',menuDisabled : true},
			{header:'接受人',dataIndex:'recipientUsername'},		
			{header:'重要程度',dataIndex:'importLevel1',menuDisabled : true},
			{header:'状态',dataIndex:'currentStatus1',menuDisabled : true},
			{header:'id',dataIndex:'id',hidden:true},
			{header:'操作',dataIndex:'operate',menuDisabled : true,renderer:function(s,m,rec){
            return "<a  href="+"javascript:workDailyTo('"+rec.data.id+"','dividerUserid')>查看</a>";
			}}
		]);
		var filters = new Ext.grid.GridFilters({
			 cleanParams: function(p) {  // 清除参数的方法，要保留PagingToolbar分页用的两个参数
			   //var regex = new RegExp("^" + this.paramPrefix + "\[[0-9]+\]");
			   for(var key in p) {
			      if( key != 'start' && key != 'limit' )
			   //if(regex.test(key)) {
			    delete p[key];
			            //}
			               }
	          },
		     buildQuery: function(filters) {	
			  // filters 就是getFilterData返回的值, 代码中push入去的对象
			  var p = {};
			  for(var i=0, len=filters.length; i<len; i++) {
			      var f = filters[i];
			      
			      // 取得在GridFilters中定义的filters中的一个filter
			      var filter = this.getFilter( f.field );
			      // 取得传递到server的参数名称
			      var name = (filter.paramName ? filter.paramName : filter.dataIndex);
			      var value = (filter.paramValue ? filter.paramValue : f.data['value']);
			      
			      if( value != '' ) p[ name ] = value;
			  }
			  return p;
			   },	
			  filters:[
			 	{type: 'string',  dataIndex: 'recipientUsername'}
		]}); 
		var url = Ext.get('url').getValue();
		sort = new Ext.data.JsonStore({
			url:url,
			fields:['beginTime1','endTime1','subject','recipientUsername','importLevel1','currentStatus1','id','operate'],
			root:'root',
			totalProperty:'totalProperty'
		});
		var bbar = new Ext.PagingToolbar({
			pageSize:10,
			store:sort,
			plugins: filters,
			displayInfo:true,
			emptyMsg:'没有记录'
		});
		
	   grid = new Ext.grid.GridPanel({
			title:'工作任务--下发',
			cm:colModel,
			renderTo:'topic-grid',
			store:sort,
			loadMask:true,
			autoHeight:true,
			tbar:[{
				 text: '接受任务',
	             iconCls: 'silk-add',
	             handler:function(){
	             	window.location.href=Ext.get('basePath').getValue()+'daily/workTask/workTaskList.jsp?dividerUserid=recipientUserid';
	             }
			},{
				 text: '下发任务',
	             iconCls: 'silk-add1',
	             handler:function(){
	             	window.location.href=Ext.get('basePath').getValue()+'daily/workTask/workTaskList.jsp?dividerUserid=dividerUserid';
	             }
			},{
				 text: '添加',
	             iconCls: 'silk-add2',
	             handler:function(){
	             	window.location.href=Ext.get('basePath').getValue()+'tjsinfo/tjsoa/workTask/workTaskTo.do';
	             }
			}],
			bbar:bbar,
			plugins: filters,
			viewConfig:{
				forceFit:true
			}
		});
		
		if(Ext.get('startid')){
			start = Ext.get('startid').getValue();
			sort.load({params:{start:0, limit: 10},callback:function(){
				grid.hide();
				bbar.hide();
				bbar.changePage(Ext.get('page').getValue());
				grid.show();
				bbar.show();
			}});
			return;
		}
		else
		{
			sort.load({params:{start:0, limit: 10}});
		}
    }
}
/**
	 * 禁用一个用户
	 * @param {} id 用户ID
	 */
	function workDailyTo(id,method){
	     window.location.href=Ext.get('basePath').getValue()+'tjsinfo/tjsoa/workTask/workTaskTo.do?id='+id+"&method="+method;			
	}
	
	